package org.example.hadoop.service.publisherFrequency;

import org.apache.hadoop.io.IntWritable;
import org.apache.hadoop.io.Text;
import org.apache.hadoop.mapreduce.Reducer;

import java.io.IOException;

/**
 * @Author: wwy
 * @Date: 2020/11/10 16:31
 */
public class PublisherFrequencyReducer extends Reducer<Text, IntWritable, Text, IntWritable> {
    /**
     * k2        v2
     * 余华       1,1,1,1
     *
     * k3        v3
     * 余华       4
     * @param key
     * @param values
     * @param context
     * @throws IOException
     * @throws InterruptedException
     */
    @Override
    protected void reduce(Text key, Iterable<IntWritable> values, Context context) throws IOException, InterruptedException {
        int count = 0;
        for (IntWritable value : values) {
            count +=value.get();
        }
        context.write(key,new IntWritable(count));
    }
}
